]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
iconGrid: Add moveItem
authorGeorges Basile Stavracas Neto <georges.stavracas@gmail.com>
Wed, 23 Sep 2020 19:52:09 +0000 (16:52 -0300)
committerFlorian Müllner <florian.muellner@gmail.com>
Mon, 5 Oct 2020 12:06:47 +0000 (12:06 +0000)
This new public API moves items without removing and readding
them, which allows us to avoid some tricky behavior. Noticeably,
following the original design described at 3555550d5, the new
IconGridLayout.moveItem() method does not call `layout_changed`.
This is done by IconGrid itself, queueing a relayout.

https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1447

js/ui/iconGrid.js

index 12a4aed9bd6ddb5935aadeb8dfb1fff9306aed61..a6a42b615a030cbfa172fc5ceb20b03e941dece6 100644 (file)
@@ -847,6 +847,22 @@ var IconGridLayout = GObject.registerClass({
         this.addItem(item);
     }
 
+    /**
+     * moveItem:
+     * @param {Clutter.Actor} item: item to move
+     * @param {int} newPage: new page of the item
+     * @param {int} newPosition: new page of the item
+     *
+     * Moves @item to the grid. @item must be part of the grid.
+     */
+    moveItem(item, newPage, newPosition) {
+        if (!this._items.has(item))
+            throw new Error(`Item ${item} is not part of the IconGridLayout`);
+
+        this._removeItemData(item);
+        this._addItemToPage(item, newPage, newPosition);
+    }
+
     /**
      * removeItem:
      * @param {Clutter.Actor} item: item to remove from the grid
@@ -1422,6 +1438,19 @@ var IconGrid = GObject.registerClass({
         this.layout_manager.appendItem(item);
     }
 
+    /**
+     * moveItem:
+     * @param {Clutter.Actor} item: item to move
+     * @param {int} newPage: new page of the item
+     * @param {int} newPosition: new page of the item
+     *
+     * Moves @item to the grid. @item must be part of the grid.
+     */
+    moveItem(item, newPage, newPosition) {
+        this.layout_manager.moveItem(item, newPage, newPosition);
+        this.queue_relayout();
+    }
+
     /**
      * removeItem:
      * @param {Clutter.Actor} item: item to remove from the grid